package org.hwadee.mapper;

import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;
import org.hwadee.entity.User;
import org.springframework.stereotype.Repository;

import java.util.List;

@Repository
public interface UserMapper {

    @Select("select * from user where username = #{username} and password = #{password} and userStatus = 1")
    User selectUserByNameAndPass(User user);

    @Select("select * from user where userId = #{userId} and userStatus = 1")
    User getUserById(Integer userId);

    @Update("update user set password = #{password}, nickname = #{nickname}, username = #{username} where userId = #{userId}")
    void updateUser(User user);

    @Insert("insert into user(username, password, nickname, sex) values (#{username}, #{password}, #{nickname}, #{sex})")
    int insertUser(User user);

    @Select("select * from user where username = #{username} and userStatus = 1")
    User selectUserByUsername(String username);

    @Select("select * from user")
    List<User> getAllUsers();

    @Update("update user set userStatus = 0 where userId = #{id}")
    void deleteUserById(Integer id);

    @Update("update user set userStatus = 1 where userId = #{id}")
    void recoveryUserById(Integer id);

    @Select("select * from user where username = #{search}")
    User getUserByUsername(String search);

    @Select("select * from user where nickname like #{search}")
    List<User> getUsersByNickname(String s);

    @Select("select nickname from user where userId = #{commentUserId}")
    String getNicknameByUserId(Integer commentUserId);
}
